/*
 *  This file is part of Fax .NET.
 *
 *  Fax .NET is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation.
 * 
 *  Fax .NET is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Fax .NET.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Tourreau.Gilles.FaxDotNet
{
    /// <summary>
    /// Represent a read-only collection of fax port devices on a <see cref="FaxServer"/>.
    /// </summary>
    public class FaxPortCollection : ReadOnlyCollection<FaxPort>
    {
        internal FaxPortCollection()
            : base(new List<FaxPort>())
        {

        }

        internal void Add(FaxPort port)
        {
            this.Items.Add(port);
        }

        internal FaxPort GetPort(uint id)
        {
            foreach (FaxPort port in this)
            {
                if (port.DeviceId == id)
                    return port;
            }

            return null;
        }

        /// <summary>
        /// Remove a port device.
        /// </summary>
        /// <param name="id">ID of port device to be delete.</param>
        internal void Remove(uint id)
        {
            this.Items.Remove(this.GetPort(id));
        }
    }
}
